#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
void print()
{
    printf("print 函数调用！\n");
    exit(3);
}
int main()
{
    while(1)
    {
        printf("I am process : pid:%d\n",getpid());
        sleep(1);
        print();
        //exit(2);//进程终止，status 进程退出时的退出码
    }
    return 0;
}
//enum{
//    success = 0,
//    open_error,
//    mallor_error
//};
//const char* errortoDesc(int code)
//{
//    switch(code)
//    {
//        case success:
//            return "success";
//        case open_error:
//            return "open_error";
//        case mallor_error:
//            return "mallor_error";
//        default:
//            return "unknow error";
//    }
//}
//int main()
//{
//    int code = success;
//    printf("%s\n",errortoDesc(code));
//    ////printf("hello linux!\n");
//    //for(int i = 0;i<200;i++)
//    //{
//    //    printf("%d : %s\n",i,strerror(i));
//    //}
//    return code;
//}
////int g_val = 100;
////int main()
////{
//    pid_t id = fork();
//    int cnt = 5;
//    if(id == 0)
//    {
//        //子进程
//        while(1)
//        {
//            printf("child: pid: %d,  ppid%d,   g_val:%d,   &g_val:%p\n",getpid(),getppid(),g_val,&g_val);
//            sleep(2);
//            cnt--;
//            if(cnt==0)
//            {
//                g_val = 200;
//                printf("g_val have change 100->200!\n");
//            }
//        }
//    }
//    else{
//        //父进程
//        while(1)
//        {
//            printf("father: pid: %d,  ppid%d,  g_val:%d,   &g_val:%p\n",getpid(),getppid(),g_val,&g_val);
//            sleep(2);
//        }
//    }
//    return 0;
//}

































//``int g_unval;
//``int g_val = 100;
//``
//``int main(int argc,char * argv[],char* env[])
//``{
//``    printf("code adder: %p\n",main);//验证代码区地址
//``    printf("init data adder: %p\n",&g_val);//验证未初始化全局变量
//``    printf("uninit data adder: %p\n",&g_unval);//验证已初始化全局变量
//``
//``    char* heap = (char*)malloc(20);
//``    char* heap1 = (char*)malloc(20);
//``    char* heap2 = (char*)malloc(20);
//``    char* heap3 = (char*)malloc(20);
//``    char* heap4 = (char*)malloc(20);
//``    static int c = 0;//验证static下变量地址 与全局变量地址一样
//``    printf("head adder: %p\n",heap);//验证堆区地址向上增长       结论：堆栈相对增长！
//``    printf("head adder: %p\n",heap1);//验证堆区地址
//``    printf("head adder: %p\n",heap2);//验证堆区地址
//``    printf("head adder: %p\n",heap3);//验证堆区地址
//``    printf("head adder: %p\n",heap4);//验证堆区地址
//``    printf("&stack adder: %p\n",&heap);//验证栈区地址向下增长
//``    printf("&stack adder: %p\n",&heap1);//验证栈区地址
//``    printf("&stack adder: %p\n",&heap2);//验证栈区地址
//``    printf("&stack adder: %p\n",&heap3);//验证栈区地址
//``    printf("&stack adder: %p\n",&heap4);//验证栈区地址
//``    printf("c adder: %p\n",&c);
//``    //验证命令行参数地址
//``    for(int i = 0;argv[i];i++)
//``    {
//``        printf("argv[%d] = %p\n",i,argv[i]);
//``    }
//``    //验证环境变量地址
//``    for(int i = 0;env[i];i++)
//``    {
//``        printf("env[%d] = %p\n",i,env[i]);
//``    }
//``
//``    return 0;
//``}
